package org.apache.commons.logging.impl.weakhashtableutils;

import java.util.Map;

/**
 * Entry implementation
 */
final class Entry implements Map.Entry {

    private final Object key;
    private final Object value;
    
    Entry(Object key, Object value) {
        this.key = key;
        this.value = value;
    }

    public boolean equals(Object o) {
        boolean result = false;
        if (o != null && o instanceof Map.Entry) {
            Map.Entry entry = (Map.Entry) o;
            result =    (getKey()==null ?
                                        entry.getKey() == null : 
                                        getKey().equals(entry.getKey()))
                        &&
                        (getValue()==null ?
                                        entry.getValue() == null : 
                                        getValue().equals(entry.getValue()));
        }
        return result;
    } 
    
    public int hashCode() {

        return (getKey()==null ? 0 : getKey().hashCode()) ^
            (getValue()==null ? 0 : getValue().hashCode());
    }

    public Object setValue(Object value) {
        throw new UnsupportedOperationException("Entry.setValue is not supported.");
    }
    
    public Object getValue() {
        return value;
    }
    
    public Object getKey() {
        return key;
    }
}